package com.woniu.liuzhougov.itemAndTask.service.impl;

import com.woniu.liuzhougov.itemAndTask.dao.DepartmentMapper;
import com.woniu.liuzhougov.itemAndTask.pojo.Department;
import com.woniu.liuzhougov.itemAndTask.service.DepartmentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @version 1.0
 * @Author zhuxinpan
 * @ClassName DepartmentServiceImpl
 * @Description
 * @Date 2019/4/23 14:49
 */
@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Resource
    private DepartmentMapper departmentMapper;

    @Override
    public List<Department> listDepartments() {
        return departmentMapper.listAllDepartments();
    }

    /**
     * @param currentPage
     * @param pageSize
     * @return java.util.List<com.woniu.liuzhougov.itemAndTask.pojo.Department>
     * @author zhuxinpan
     * @date 2019/4/28 21:50
     * @description 列出部门(分页展示)
     */
    @Override
    public List<Department> listDepartments(Integer currentPage, Integer pageSize) {
        return departmentMapper.listDepartments(currentPage,pageSize);
    }

    /**
     * @param department
     * @return int
     * @author zhuxinpan
     * @date 2019/4/28 23:10
     * @description 添加部门
     */
    @Override
    public int insertDepartment(Department department) {
        department.setLeader(null);
        department.setDepartmentId(null);
        return departmentMapper.insertSelective(department);
    }

    /**
     * @param department
     * @return int
     * @author zhuxinpan
     * @date 2019/4/28 23:14
     * @description 统计部门名称
     */
    @Override
    public int countByDepartmentName(Department department) {
        return departmentMapper.countByDepartmentName(department);
    }

    /**
     * @param departmentId
     * @return com.woniu.liuzhougov.itemAndTask.pojo.Department
     * @author zhuxinpan
     * @date 2019/4/28 23:55
     * @description 通过主键获得部门详情
     */
    @Override
    public Department getDepartmentByDepartmentId(Integer departmentId) {
        return departmentMapper.selectByPrimaryKey(departmentId);
    }

    /**
     * @param department
     * @return int
     * @author zhuxinpan
     * @date 2019/4/28 23:56
     * @description 更新部门
     */
    @Override
    public int updateDepartment(Department department) {
        department.setLeader(null);
        return departmentMapper.updateByPrimaryKeySelective(department);
    }

    /**
     * @param department
     * @return int
     * @author zhuxinpan
     * @date 2019/4/29 0:33
     * @description 更新部门领导
     */
    @Override
    public int updateLeaderId(Department department) {
        department.setDepartmentName(null);
        return departmentMapper.updateByPrimaryKeySelective(department);
    }

    /**
     * @param departmentId
     * @return int
     * @author zhuxinpan
     * @date 2019/4/29 0:56
     * @description 删除部门
     */
    @Override
    public int deleteDepartmentByDepartmentId(Integer departmentId) {
        return departmentMapper.deleteByPrimaryKey(departmentId);
    }
}
